stk_help = '''System Tool Kit usage:
    - stk help : Print help

  Memory:
    - stk memdump : Dump memory
    - stk meminfo : Print memory info
    - stk collect : Collect Garbage

  Machine:
    - stk bootloader : Reset machine to bootloader
    - stk getid : Get machine ID
    - stk irq off : Disables IRQ
    - stk lightsleep (duration) : Get machine to lightsleep. Duration in ms.

  CPU:
    - stk freq : Get CPU frequency
'''

class STK:
    def handle(self):
        if len(self.cmd) == 1:
            print(stk_help)
        elif len(self.cmd) == 2:
            if self.cmd[1] == "memdump":
                import micropython
                micropython.mem_info(True)
            if self.cmd[1] == "meminfo":
                import micropython
                micropython.mem_info()
            if self.cmd[1] == "bootloader":
                import machine
                machine.bootloader(True)
            if self.cmd[1] == "getid":
                import machine
                print(f'Machine ID: {machine.unique_id()}')
            if self.cmd[1] == "collect":
                import gc
                bytes_collected = gc.collect()
        elif len(self.cmd) == 3:
            if self.cmd[1] == "irq":
                if self.cmd[2] in ['off', 'disable']:
                    import machine
                    print('IRQ Disabled. StateID: {machine.disable_irq()}')
            if self.cmd[1] == 'cpu':
                import machine
                if self.cmd[2] == "freq":
                    print(f'CPU Frequency: {machine.freq() // 1_000_000} MHz')
                if self.cmd[2] == 'idle':
                    machine.idle() # что...
            if self.cmd[1] == "lightsleep":
                import machine
                machine.lightsleep(int(self.cmd[2]))

        else:
            print(stk_help)

    def process(self, command):
        command = command.strip()
        self.cmd = command.split(' ') if ' ' in command else [command]
        self.handle()

#cmd = 'stk collect'

STK().process(cmd)

